package org.jeecg.modules.golf.question.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.golf.question.client.StatisticsQuestionStatusDTO;
import org.jeecg.modules.golf.question.client.qto.StatisticsQuestionAnalysisQueryDTO;
import org.jeecg.modules.golf.question.entity.QuestionStatusRecord;
import org.jeecg.modules.golf.question.event.QuestionStatusEvent;
import org.jeecg.modules.golf.question.mapper.QuestionStatusRecordMapper;
import org.jeecg.modules.golf.question.service.IQuestionStatusRecordService;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

/**
 * @Description: 问题状态更新记录表
 * @Author: jeecg-boot
 * @Date:   2020-11-06
 * @Version: V1.0
 * 学员的问题状态分析
 */
@Service
public class QuestionStatusRecordServiceImpl extends ServiceImpl<QuestionStatusRecordMapper, QuestionStatusRecord> implements IQuestionStatusRecordService {


    /**
     * 保存问题状态变更
     * @param questionStatusEvent
     */
    @EventListener
    public void handleEvent(QuestionStatusEvent questionStatusEvent){
        QuestionStatusRecord questionStatusRecord = new QuestionStatusRecord();
        questionStatusRecord.setQuestionId(questionStatusEvent.getQuestion().getId());
        questionStatusRecord.setQuestionStatus(questionStatusEvent.getQuestion().getQuestionStatus());
        questionStatusRecord.setTraineeId(questionStatusEvent.getQuestion().getTrainee());
        save(questionStatusRecord);
    }





    /**
     * 统计问题状态
     *
     * @param statisticsQuestionStatusQTO
     * @return
     */
    @Override
    public StatisticsQuestionStatusDTO statisticStatus(StatisticsQuestionAnalysisQueryDTO statisticsQuestionStatusQTO) {
        return getBaseMapper().statisticStatus(statisticsQuestionStatusQTO);
    }
}
